<?php
class EncryptComponent extends Object{
	
	var $key_len;
	var $prop;
	var $key = "kamome";
	function __construct(){
		$this->prop = new PropComponent();
		$this->key_len = strlen($this->key);
	}
	
	function encode(&$data){
//		$key = $this->randKey($this->key_len);
		$key = $this->key;
		$data = base64_encode($key . "|" . $data . "|" . $key);
	}
	
	function decode(&$data){
		$data = base64_decode($data);
		$data = substr($data, $this->key_len + 1);
		$data = substr($data, 0, - ($this->key_len + 1));
	}
	
	function randKey($len){
		$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-@#'; 
	    mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
	
	    $key='';
	
	    while(strlen($key)<$len)
	        $key .= substr($chars,(mt_rand()%strlen($chars)),1);
	
	    return $key;
	}
}